#include "includes.h"

const u8 EnterCmd14230HL[5] =
{
    0xc1, 0x33, 0xf1, 0x81, 0x66
};

u8 DSCmd14230HL[6] =
{
    0xc2, 0x33, 0xf1, 0x01, 0x00, 0x00
};

const u8 CDTCCmd14230HL[5] =
{
    0xc1, 0x33, 0xf1, 0x04, 0xe9
};

//active
void hl_25ms(void);

int iso14230_4hl_link(void)
{
    int ret;
    ErrorStatus err;

    printk("Link...\r\n");
    //active
    hl_25ms();
    send_kwp2000_frame((u8 *)EnterCmd14230HL, &err);
    if(err == SUCCESS) {
        printk("OK\r\n");
        ret = 0;
        //delay 1s
        OSTimeDly(OS_TICKS_PER_SEC * 1);
    } else {
        ret = -1;
    }

    return ret;
}

int iso14230_4hl_clear_error_code(void)
{
    int ret;
    ErrorStatus err;

    send_kwp2000_frame((u8 *)&CDTCCmd14230HL, &err);
    if(err == SUCCESS) {
        ret = 0;
    } else {
        printk("%s: failed to do cdtc\r\n", __func__);
        ret = -1;
    }

    return ret;
}

s16 iso14230_4hl_readEnginSpeed(void)
{
    ErrorStatus err;
    s16 val = -1;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x0c;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) / 4;
    } else {
        val = -1;
    }

    return val;
}

u8 iso14230_4hl_get_payload(void)
{
    ErrorStatus err;
    u8 val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x04;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ram[5] * 100 / 255;
    } else {
        val = 0xff;
    }

    return val;
}

u8 iso14230_4hl_get_ect(void)
{
    ErrorStatus err;
    u8 val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x05;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ram[5] - 40;
    } else {
        val = 0xff;
    }

    return val;
}
u16 iso14230_4hl_get_speed(void)
{
    ErrorStatus err;
    u16 val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x0d;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ram[5];
    } else {
        val = 0xffff;
    }

    return val;
}

void hl_25ms(void)
{
    kl_line_enable(K_LINE);
    GPIO_WriteBit(KL_LINE_IO, KL_LINE_TXD, Bit_SET);
    //delay 3s
    OSTimeDly(OS_TICKS_PER_SEC * 3);

    GPIO_WriteBit(KL_LINE_IO, KL_LINE_TXD, Bit_RESET);
    //delay 25ms
    OSTimeDly(OS_TICKS_PER_SEC / 40);
    GPIO_WriteBit(KL_LINE_IO, KL_LINE_TXD, Bit_SET);
    //delay 25ms
    OSTimeDly(OS_TICKS_PER_SEC / 40);
    kl_line_config(10400);
}


u16 iso14230_4hl_get_mil_distance(void)
{
    ErrorStatus err;
    u16 val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x21;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = (ram[5] << 8) | (ram[6]);
    } else {
        val = 0xffff;
    }

    return val;
}

float iso14230_4hl_get_relative_frp(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x22;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 5177.27 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_frp(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x23;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 10;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_ratio_1_1(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x24;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_o2vol_1_1(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x24;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 7999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_ratio_1_2(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x25;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_o2vol_1_2(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x25;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 7999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_ratio_1_3(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x25;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_o2vol_1_3(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x26;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 7999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_ratio_1_4(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x27;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_o2vol_1_4(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x27;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 7999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_ratio_2_1(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x28;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_o2vol_2_1(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x28;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 7999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_ratio_2_2(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x29;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_o2vol_2_2(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x29;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 7999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_ratio_2_3(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x2A;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_o2vol_2_3(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x2A;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 7999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_ratio_2_4(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x2b;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_o2vol_2_4(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x2b;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 7999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_egr(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x2c;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ram[5] * 100 / 255;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_egr_error(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x2d;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ram[6] * 100 / 128 - 100;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_ioep(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x2e;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ram[5] * 100 / 255;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_fuel_level_input(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x2f;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ram[5] * 100 / 255;
    } else {
        val = -1;
    }

    return val;
}

u16 iso14230_4hl_get_after_start_times(void)
{
    ErrorStatus err;
    u16 val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x30;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ram[5];
    } else {
        val = 0xffff;
    }

    return val;
}

u16 iso14230_4hl_get_after_distance(void)
{
    ErrorStatus err;
    u16 val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x31;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = (ram[5] << 8) | ram[6];
    } else {
        val = 0xffff;
    }

    return val;
}

u16 iso14230_4hl_get_emission_sys_press(void)
{
    ErrorStatus err;
    u16 val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x32;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) / 4;
    } else {
        val = 0xffff;
    }

    return val;
}

u16 iso14230_4hl_get_press(void)
{
    ErrorStatus err;
    u16 val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230;
    
    DSCmd14230HL[4] = 0x33;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ram[5];
    } else {
        val = 0xffff;
    }

    return val;
}

float iso14230_4hl_get_o2cur_1_1(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230HL;
    
    DSCmd14230HL[4] = 0x34;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_ratio2_1_1(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230HL;
    
    DSCmd14230HL[4] = 0x34;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 256 / 65535 - 128;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_o2cur_1_2(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230HL;
    
    DSCmd14230HL[4] = 0x35;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_ratio2_1_2(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230HL;
    
    DSCmd14230HL[4] = 0x35;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 256 / 65535 - 128;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_o2cur_1_3(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230HL;
    
    DSCmd14230HL[4] = 0x36;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_ratio2_1_3(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230HL;
    
    DSCmd14230HL[4] = 0x36;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 256 / 65535 - 128;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_o2cur_1_4(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230HL;
    
    DSCmd14230HL[4] = 0x37;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_ratio2_1_4(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230HL;
    
    DSCmd14230HL[4] = 0x37;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 256 / 65535 - 128;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_o2cur_2_1(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230HL;
    
    DSCmd14230HL[4] = 0x38;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_ratio2_2_1(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230HL;
    
    DSCmd14230HL[4] = 0x38;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 256 / 65535 - 128;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_o2cur_2_2(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230HL;
    
    DSCmd14230HL[4] = 0x39;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_ratio2_2_2(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230HL;
    
    DSCmd14230HL[4] = 0x39;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 256 / 65535 - 128;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_o2cur_2_3(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230HL;
    
    DSCmd14230HL[4] = 0x3a;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_ratio2_2_3(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230HL;
    
    DSCmd14230HL[4] = 0x3a;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 256 / 65535 - 128;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_o2cur_2_4(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230HL;
    
    DSCmd14230HL[4] = 0x3b;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) * 1.999 / 65535;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_ratio2_2_4(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230HL;
    
    DSCmd14230HL[4] = 0x3b;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[7] << 8) | ram[8]) * 256 / 65535 - 128;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_cat_temp_1_1(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230HL;
    
    DSCmd14230HL[4] = 0x3c;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) / 10 - 40;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_cat_temp_1_2(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230HL;
    
    DSCmd14230HL[4] = 0x3d;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) / 10 - 40;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_cat_temp_2_1(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230HL;
    
    DSCmd14230HL[4] = 0x3e;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) / 10 - 40;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_cat_temp_2_2(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230HL;
    
    DSCmd14230HL[4] = 0x3f;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ((ram[5] << 8) | ram[6]) / 10 - 40;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_short_fuel_adj_1(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230HL;
    
    DSCmd14230HL[4] = 0x06;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ram[5] * 100 / 128 - 100;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_long_fuel_adj_1(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230HL;
    
    DSCmd14230HL[4] = 0x07;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ram[5] * 100 / 128 - 100;
    } else {
        val = -1;
    }

    return val;
}

float iso14230_4hl_get_short_fuel_adj_2(void)
{
    float val = -1;    
    printk("Unsupported!\r\n");

    return val;
}

float iso14230_4hl_get_long_fuel_adj_2(void)
{
    float val = -1;    
    printk("Unsupported!\r\n");

    return val;
}

u8 iso14230_4hl_get_gas_temp(void)
{
    ErrorStatus err;
    u8 val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230HL;
    
    DSCmd14230HL[4] = 0x0f;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ram[5] - 40;
    } else {
        val = 0xff;
    }

    return val;
}

float iso14230_4hl_get_throttle_pos(void)
{
    ErrorStatus err;
    float val = 0;
    u8 *ram;
    //u8 *cmd = &DSCmd14230HL;
    
    DSCmd14230HL[4] = 0x11;
    ram = send_kwp2000_frame(DSCmd14230HL, &err);
    if(err == SUCCESS) {
        val = ram[5] * 100 / 255;
    } else {
        val = -1;
    }

    return val;
}
